<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-menu.tld" prefix="menu" %>
<%@ taglib uri="/WEB-INF/tlds/struts-menu-el.tld" prefix="menu-el" %>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tlds/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tlds/authz.tld" prefix="authz" %>
<%@ taglib uri="/WEB-INF/tlds/sitemesh-decorator.tld" prefix="decorator"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" scope="request"/>
<script type="text/javascript" src="${ctx}/dwr/interface/ConfigSaverDWR.js"></script>
<script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
<script type="text/javascript" src="${ctx}/dwr/util.js"></script>
<script type="text/javascript">
<!--
	function savePool() {
		var min = $F("min");
		var max = $F("max");
		var timeout = $F("timeout");
		if(!min || min.length==0 || !isNumber(min)) {
			alert('<bean:message key="error.minPoolSizeNumber" />');
		} else if(!max || max.length==0 || !isNumber(max)) {
			alert('<bean:message key="error.maxPoolSizeNumber" />');
		} else if(parseInt(max)<parseInt(min)) {
			alert('<bean:message key="error.minInferiorToMax" />');
		} else if(!timeout || timeout.length==0 || !isNumber(timeout)) {
			alert('<bean:message key="error.timeoutNumber" />');
		} else {
			$('method').value='save';
			$('connectionForm').submit();
		}
	}
	function saveConfig() {
		var id = $F("id");
		ConfigSaverDWR.saveConnectionConfig(message,id);
	}
	function message(ret) {
		var id = $F("id");
		if(ret) {
			alert('<bean:message key="info.saveDone"/>');
			this.location = '${ctx}/connection.do?method=edit&amp;forward=pool&amp;id='+id;
		} else {
			alert('<bean:message key="info.saveNotDone"/>');
		}
	}
// -->					
</script>
<div id="tabPanelWrapper">
	<html:form styleId="connectionForm" action="/connection" focus="min">
		<div id="tabPanel">
			<ul>
			  <li><html:link action="/connection?method=edit&amp;forward=connection" paramId="id" paramProperty="connection.id" paramName="connectionForm"><bean:message key="connectionPoolPage.connectionTab" /></html:link></li>
			  <li><html:link styleId="currentTab" action="/connection?method=edit&amp;forward=pool" paramId="id" paramProperty="connection.id" paramName="connectionForm"><bean:message key="connectionPoolPage.poolTab" /></html:link></li>
			</ul>
		</div>
		<div id="tabContent">
			<h1><bean:write property="connection.name" name="connectionForm"/></h1>
			<div id="subcontent">
				<input type="hidden" name="method" value="" id="method"/>
				<input type="hidden" name="forward" value="pool" id="forward"/>
				<html:hidden property="connection.id" styleId="id"/>
				<html:hidden property="connection.name"/>
<authz:authorize ifAllGranted="ROLE_SUPERVISOR">								
				<p><bean:message key="poolPage.minSizePool" />: <html:text property="connection.minPoolSize" maxlength="127" styleId="min" onmouseover="this.T_BGCOLOR='#D7D7ff';this.T_FONTFACE='Arial, Helvetica';this.T_FONTSIZE='12px';return escape('Taille minimale du pool de connexion \<br\/\>\<i\>Ex: 10\<\/i\>');"/></p>
				<p><bean:message key="poolPage.maxSizePool" />: <html:text property="connection.maxPoolSize" maxlength="127" styleId="max" onmouseover="this.T_BGCOLOR='#D7D7ff';this.T_FONTFACE='Arial, Helvetica';this.T_FONTSIZE='12px';return escape('Taille maximale du pool de connexion \<br\/\>\<i\>Ex: 30\<\/i\>');"/></p>
				<p><bean:message key="poolPage.timeoutPool" />: <html:text property="connection.timeoutPool" maxlength="127" styleId="timeout" onmouseover="this.T_BGCOLOR='#D7D7ff';this.T_FONTFACE='Arial, Helvetica';this.T_FONTSIZE='12px';return escape('Timeout de connexion LDAP en millisecondes\<br\/\>\<i\>Ex: 2000\<\/i\>');"/></p>
				<p><input name="validatePoolButton" type="submit" value="<bean:message key='poolPage.validate' />" onclick="savePool();return false;"/>&nbsp;<input name="cancelPoolButton" type="reset" value="<bean:message key='poolPage.cancel' />"/></p>
</authz:authorize>
<authz:authorize ifAllGranted="ROLE_USER">								
				<p><bean:message key="poolPage.minSizePool" />: <bean:write name="connectionForm" property="connection.minPoolSize" /></p>
				<html:hidden name="connectionForm" property="connection.minPoolSize" styleId="min" />
				<p><bean:message key="poolPage.maxSizePool" />: <bean:write name="connectionForm" property="connection.maxPoolSize" /></p>
				<p><bean:message key="poolPage.timeoutPool" />: <bean:write name="connectionForm" property="connection.timeoutPool" /></p>
</authz:authorize>
			</div>
			<p>
<authz:authorize ifAllGranted="ROLE_SUPERVISOR">								
				<input type="submit" value="<bean:message key='allPage.saveConfig' />" onclick="saveConfig();return false;"/>
</authz:authorize>
			</p>
		</div>
	</html:form>
</div>